package com.ynny.dao;

import com.ynny.bean.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class StudentDaoImpl implements StudentDao{
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public boolean login(Student student) {
       String sql = "select * from student where number = ? and name = ? and grade = ? and sex= ？" ;
        Object [] Obj= new Object[]{
                student.getNumber(),
                student.getName(),
                student.getGrade(),
                student.getSex()
        };
        RowMapper<Student>rowMapper;
        rowMapper = new BeanPropertyRowMapper<Student>(Student.class);
        List<Student> list = jdbcTemplate.query(sql,rowMapper,Obj);
        if(list.size()>0){
            return true;
        }
        return false;
    }

    @Override
    public void quit() {
        System.out.println("退出登录");

    }

    @Override
    public boolean FindAll() {
        return false;
    }

    @Override
    public boolean FindByNumber(String number) {
        return false;
    }
}
